/*此处是年月日的js*/
function YYYYMMDDstart(){   
		MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];   
		
		//先给年下拉框赋内容   
		var y  = new Date().getFullYear();  
		for (var i = (y-60); i < (y-18); i++) //以今年为准，前30年，后30年   
			   document.reg_testdate.YYYY.options.add(new Option(" "+ i +" 年", i));   
		
		//赋月份的下拉框   
		for (var i = 1; i < 13; i++)   
			   document.reg_testdate.MM.options.add(new Option(" " + i + " 月", i));   
		
		document.reg_testdate.YYYY.value = y;   
		document.reg_testdate.MM.value = new Date().getMonth() + 1;   
		var n = MonHead[new Date().getMonth()];   
		if (new Date().getMonth() ==1 && IsPinYear(y)) n++;   
			writeDay(n); //赋日期下拉框Author:meizz   
		document.reg_testdate.DD.value = new Date().getDate();   
	}   
	if(document.attachEvent)   
		window.attachEvent("onload", YYYYMMDDstart);   
	else   
	window.addEventListener('load', YYYYMMDDstart, false);   
	function YYYYDD(str) //年发生变化时日期发生变化(主要是判断闰平年)   
	{   
		var MMvalue = document.reg_testdate.MM.options[document.reg_testdate.MM.selectedIndex].value;   
		if (MMvalue == ""){ var e = document.reg_testdate.DD; optionsClear(e); return;}   
		var n = MonHead[MMvalue - 1];   
		if (MMvalue ==2 && IsPinYear(str)) n++;   
		writeDay(n)   
	}   
	function MMDD(str)   //月发生变化时日期联动   
	{   
		var YYYYvalue = document.reg_testdate.YYYY.options[document.reg_testdate.YYYY.selectedIndex].value;   
		if (YYYYvalue == ""){ var e = document.reg_testdate.DD; optionsClear(e); return;}   
		var n = MonHead[str - 1];   
		if (str ==2 && IsPinYear(YYYYvalue)) n++;   
		writeDay(n)   
	}   
	function writeDay(n)   //据条件写日期的下拉框   
	{   
		var e = document.reg_testdate.DD; optionsClear(e);   
		for (var i=1; i<(n+1); i++)   
		e.options.add(new Option(" "+ i + " 日", i));   
	}   
	function IsPinYear(year)//判断是否闰平年   
	{
		return(0 == year%4 && (year%100 !=0 || year%400 == 0));
	}   
	function optionsClear(e)   
	{   
		e.options.length = 1;   
	}
		
/*此处是属相的js*/
	function getpet () { 
				var toyear = 1997; 
				var birthyear = document.reg_testdate.YYYY.value; 
				var birthpet="Ox" 
				x = (toyear - birthyear) % 12 
				if ((x == 1) || (x == -11)) { 
					birthpet="鼠"      
				}else  { 
					if (x == 0){ 
						birthpet="牛"           
					}else  { 
					  if ((x == 11) || (x == -1)) { 
						 birthpet="虎"          
					  } else  { 
						if ((x == 10) || (x == -2)) { 
							birthpet="兔"         
						}else { 
							if ((x == 9) || (x == -3))  { 
								birthpet="龙"         
							}else  { 
								if ((x == 8) || (x == -4))  {  
									birthpet="蛇"      
								} else  { 
									if ((x == 7) || (x == -5))  {  
										birthpet="马"      
									}else  { 
										if ((x == 6) || (x == -6))  {  
											birthpet="羊"     
										}  else  { 
											if ((x == 5) || (x == -7))  {   
												birthpet="猴"     
											} else  { 
												if ((x == 4) || (x == -8))  { 
													birthpet="鸡"    
												}  else  { 
													if ((x == 3) || (x == -9))  { 
														birthpet="狗"        
													}  else  { 
														 if ((x == 2) || (x == -10))  { 
															birthpet="猪"         
														}   
													} 
												 } 
											} 
										} 
									} 
								} 
							} 
						} 
					 } 
				} 
			} 
				document.frm.birth.value = birthpet; 
		} 
								
/*此处是星座的js*/

function xingzuo() {
		var start = 1901;
		var date=document.reg_testdate.DD.value; 
		var month=document.reg_testdate.MM.value;
		var xingz="";
		if (month == 1 && date >=20 || month == 2 && date <=18) {
			xingz = "水瓶座";
		}else{
			if (month == 2 && date >=19 || month == 3 && date <=20) {
				xingz = "双鱼座";
			}else{
				if (month == 3 && date >=21 || month == 4 && date <=19) {
					xingz = "白羊座";
				}else{
					if (month == 4 && date >=20 || month == 5 && date <=20) {
						xingz = "金牛座";
					}else{
						if (month == 5 && date >=21 || month == 6 && date <=21) {
							xingz = "双子座";
						}else{
							if (month == 6 && date >=22 || month == 7 && date <=22) {
								xingz = "巨蟹座";
							}else{
								if (month == 7 && date >=23 || month == 8 && date <=22) {
									xingz = "狮子座";
								}else{
									if (month == 8 && date >=23 || month == 9 && date <=22) {
										xingz = "处女座";
									}else{
										if (month == 9 && date >=23 || month == 10 && date <=22) {
											value = "天秤座";
										}else{
											if (month == 10 && date >=23 || month == 11 && date <=21) {
												xingz = "天蝎座";
											}else{
												if (month == 11 && date >=22 || month == 12 && date <=21) {
													xingz = "射手座";
												}else{
													if (month == 12 && date >=22 || month == 1 && date <=19) {
														xingz = "摩羯座";
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		document.wxz.wxing.value = xingz;
	}

/*点击保存后*/

function ziliaoInfo(){
	
	var nickname=$("#nickname").val();
	var sex=$(".wsex   option:selected").text().trim();
	var birthDay=$("#dateYYYY").val().trim()+"-"+$("#dateMM").val().trim()+"-"+$("#dateDD").val().trim();
	var animal=$("#My_animal").val();
	var constellation=$("#My_constellation").val();
	var height=$("#height .sel01 option:selected").text().trim();
	var education=$("#education .sel01 option:selected").text().trim();
	var works=$("#occupation .sel01 option:selected").text().trim();
	var marriage=$("#marriage   option:selected").text().trim();
	var children=$("#children   option:selected").text().trim();
	var xianarea=$("#province option:selected").text().trim()+"-"+$("#city option:selected").text().trim();
	var hometown=$("#homeprovince option:selected").text().trim()+"-"+$("#homecity option:selected").text().trim();
	var income=$("#income   option:selected").text().trim();
	var ifhome=$("#housing   option:selected").text().trim();
	var ifchar=$("#car   option:selected").text().trim();
	var phone=$("#mobileContact").val();
	var temp1=$("#phoneContact").val();
	var weixin=$("#weiXinContact").val();
	var qq=$("#qqContact").val();
	var other=$("#otherContact").val();
	
	$.post("mybaiheServlet?t="+new Date(),{op:'ziliaoInfo',nickname:nickname,sex:sex,birthDay:birthDay,animal:animal,constellation:constellation,
		height:height,education:education,works:works,marriage:marriage,children:children,xianarea:xianarea,hometown:hometown,
		income:income,ifhome:ifhome,ifchar:ifchar,phone:phone,email:temp1,weixin:weixin,qq:qq,other:other
	},function(data){
		data=parseInt($.trim(data));
		if(data==1){
			alert("保存成功。。。")
			location.href="photoTest.html";
		}else{
			alert("保存失败。。。。");
		}
	});

}


/*省市级联*/

/*
大多数浏览器都有读取和操作 XML 的内建 XML 解析器,微软IE基于ActiveX的MSXML
解析器把 XML 转换为 JavaScript 可访问的XML DOM对象
*/
function createIEXmlDom(){
	var arrs=["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0","MSXML2.DOMDocument","Microsoft.XmlDom"];
	var ieXmlDom;
	for(var i=0;i<arrs.length;i++){
		try{
			ieXmlDom=new ActiveXObject(arrs[i]);
			return ieXmlDom;
		}catch(e){
			
		}
	}
	throw new Error("对不起,您的浏览器不支持...");
}

function xmlDom(){
	var dom;
	if(window.ActiveXObject){  //IE获取XML文档对象
		dom=createIEXmlDom();
	}else if(document.implementation&&document.implementation.createDocument){ //implementation：正在运行的程序
		//第一个参数是命名空间   第二个参数是跟标签   第三个一个doc类型
		dom=document.implementation.createDocument("","",null);
	}else{ //抛出异常
		throw new Error("对不起,您的浏览器不支持...");
	}
	return dom;
}

function xmlDoms(){
	var dom;
	if(window.ActiveXObject){  //IE获取XML文档对象
		dom=createIEXmlDom();
	}else if(document.implementation&&document.implementation.createDocument){ //implementation：正在运行的程序
		//第一个参数是命名空间   第二个参数是跟标签   第三个一个doc类型
		dom=document.implementation.createDocument("","",null);
	}else{ //抛出异常
		throw new Error("对不起,您的浏览器不支持...");
	}
	return dom;
}

function nowcity() {
	var dom;
	if(window.DOMParser&&!window.ActiveXObject){
		var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET","js/city.xml",false);
		xmlhttp.send(null);
		if(xmlhttp.readyState==4){
			dom=xmlhttp.responseXML.documentElement;
		}
	}else{
		dom=xmlDom();
		dom.async=false;
		dom.load("js/city.xml");
	}
	
	//获取显示三级级联的三个下拉对象
	var pro=document.getElementById("province");
	var city=document.getElementById("city");
	
	//获取所有的省份
	var pros=dom.getElementsByTagName("province");
	for(var i=0;i<pros.length;i++){
		addOption(pros[i],pro);
	}
	
	//当省份发生改变时，后面的城市跟着改变,所以给省份的下拉对象添加一个onchange事件
	pro.onchange=function(){
		//获取当前选中的省份的编号
		var flag=pro.value;
		
		//清空以前的数据
		city.length=1;
		
		for(var i=0;i<pros.length;i++){
			//如果选中的省份的编号跟当前循环的对象编号一样
			if(pros[i].nodeType==1&&flag==pros[i].getAttribute("postcode")){
				//取出该省份下的所有市
				var cities=pros[i].childNodes;
				for(var j=0;j<cities.length;j++){
					if(cities[j].nodeType==1){
						addOption(cities[j],city);
					}
				}
				break;
			}
		}
	}
	
}


function homecity() {
	var dom;
	if(window.DOMParser&&!window.ActiveXObject){
		var xmlhttp=new XMLHttpRequest();
		xmlhttp.open("GET","js/city.xml",false);
		xmlhttp.send(null);
		if(xmlhttp.readyState==4){
			dom=xmlhttp.responseXML.documentElement;
		}
	}else{
		dom=xmlDoms();
		dom.async=false;
		dom.load("js/city.xml");
	}
	
	//获取显示三级级联的三个下拉对象
	var pro=document.getElementById("homeprovince");
	var city=document.getElementById("homecity");
	
	//获取所有的省份
	var pros=dom.getElementsByTagName("province");
	
	for(var i=0;i<pros.length;i++){
		addOption(pros[i],pro);
	}
	
	//当省份发生改变时，后面的城市跟着改变,所以给省份的下拉对象添加一个onchange事件
	pro.onchange=function(){
		//获取当前选中的省份的编号
		var flag=pro.value;
		
		//清空以前的数据
		city.length=1;
		
		for(var i=0;i<pros.length;i++){
			//如果选中的省份的编号跟当前循环的对象编号一样
			if(pros[i].nodeType==1&&flag==pros[i].getAttribute("postcode")){
				//取出该省份下的所有市
				var cities=pros[i].childNodes;
				for(var j=0;j<cities.length;j++){
					if(cities[j].nodeType==1){
						addOption(cities[j],city);
					}
				}
				break;
			}
		}
	}
	
}


//第一个是要添加的节点对象，第二个是要添加到的对象
function addOption(node,obj){
	if(node.nodeType==1){
		var opt=document.createElement("option");
		opt.appendChild( document.createTextNode( node.getAttribute("name") ) );
		opt.setAttribute("value",node.getAttribute("postcode"));
		obj.appendChild(opt);
		//<option value=''>湖南省</option>
	}
}


